from utils.read_config import get_config_from_api_para
from dashscope import MultiModalConversation

# You can set by dashscope.api_key = your_api_key in code,
# or you can set it via environment variable DASHSCOPE_API_KEY= your_api_key. 
# You can store your api key to a file, and use dashscope.api_key_file_path=api_key_file_path in code,
# or you can set api key file path via environment variable DASHSCOPE_API_KEY_FILE_PATH, You can call save_api_key to api_key_file_path or default path(~/.dashscope/api_key).

def call_with_local_file(img_list):
    api_key = get_config_from_api_para('api_key')
    content = [{'image': 'file://' + path} for path in img_list]

    messages = [{
        'role': 'system',
        'content': [{
            'text': 'You are a helpful assistant.'
        }]
    }, {
        'role': 'user',
        'content': content + [{'text': '说出这几张图片里都有什么?只需要列出内容即可'}]
    }]

    response = MultiModalConversation.call(api_key = api_key, model='qwen-vl-chat-v1', messages=messages)
    content = response["output"]["choices"][0]["message"]["content"]
    return content.split("\n")

